<?php
set_time_limit(0);
$root=preg_replace('/cron$/', '', dirname(__FILE__));

require_once($root."inc.config.php");

require_once($root."initialize.php");

if(($db_msg=cron_initialize()) !== true){

	print_r("Connection error");

}else{ 

	$db=$vars["db"];

	
		$t = @mysql_num_rows($r=mysql_query("SELECT * FROM gg_users_20140429 ORDER BY ref, matrix_upline"));
		
		if($t<=0)
		{
			print_r("no record");
			exit;
		}
		
		$uid=0;
		$bal=0;
		$num=0;
		while($users = mysql_fetch_assoc($r))
		{
			$main_id = 0;
			$arr_user = array();
			for($i=1; $i<=15; $i++){
				if($i==1){
					$sponsor_id=0;
					if($users['ref']>0){
						$sponsor_username = @mysql_result(mysql_query("select username from gg_users_20140429 where id=".$users['ref']), 0) or 0;
						$sponsor_id = @mysql_result(mysql_query("select id from gg_users where username='".str_replace("'","\'",$sponsor_username)."'"), 0) or 0;
					}
					
					$placement_id=0;
					if($users['matrix_upline']>0){
						$placement_username = @mysql_result(mysql_query("select username from gg_users_20140429 where id=".$users['matrix_upline']), 0) or 0;
						if($users['matrix_position']=='1')
							$placement_id = @mysql_result(mysql_query("select id from gg_users where username='".str_replace("'","\'",$placement_username)."-8'"), 0) or 0;
						else
							$placement_id = @mysql_result(mysql_query("select id from gg_users where username='".str_replace("'","\'",$placement_username)."-15'"), 0) or 0;
					}
					
					$sql = "INSERT INTO gg_users (code,name,username,password,enc_password,ewallet_password,ewallet_enc_password,epoint_password,epoint_enc_password,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino) values ('".$users['code']."','".$users['name']."','".$users['username']."','".$users['password']."','".$users['enc_password']."','".$users['ewallet_password']."','".$users['ewallet_enc_password']."','".$users['epoint_password']."','".$users['epoint_enc_password']."','".$sponsor_id."','0','".$placement_id."','".$users['matrix_position']."','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."')";
					mysql_query($sql);
					$main_id = mysql_insert_id();
					$arr_user[$i] = $main_id; 
				}else{
					if($i==2)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['1']."','1','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==3)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['1']."','2','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==4)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['2']."','1','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==5)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['2']."','2','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==6)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['3']."','1','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==7)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['3']."','2','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==8)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['4']."','1','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==9)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['4']."','2','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==10)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['5']."','1','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==11)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['5']."','2','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==12)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['6']."','1','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==13)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['6']."','2','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==14)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['7']."','1','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					elseif($i==15)
						$sql = "INSERT INTO gg_users (code,name,username,ref,rank_a,matrix_upline,matrix_position,email,ic,address,address2,city,zip,state,country,homeno,mobileno,dob,acc_type,status,activated,cdate,is_casino,main_uid) values ('".$users['code']."-".$i."','".$users['name']."','".str_replace("'","\'",$users['username'])."-".$i."','".$sponsor_id."','0','".$arr_user['7']."','2','".$users['email']."','".$users['ic']."','".$users['address']."','".$users['address2']."','".$users['city']."','".$users['zip']."','".$users['state']."','".$users['country']."','".$users['homeno']."','".$users['mobileno']."','".$users['dob']."','".$users['acc_type']."','".$users['status']."','".$users['activated']."','".$users['cdate']."','".$users['is_casino']."','".$main_id."')";
					
					mysql_query($sql);
					$arr_user[$i] = mysql_insert_id();
					
				}
			}
			
			$num++;
			//if($num==100) break;
		}

	print_r("finish");
}
?>